/**
 * 公共方法文件
 */
import store from '@/store';

/**
 * 校验权限
 * @param codes 
 */
export const valid = (codes: string | string[]) => {
    if (!codes) return true;
    if (typeof codes === 'string') {
        return store.state.myMenus.some(c => c.code === codes);
    }
    return store.state.myMenus.some(c => codes.includes(c.code));
}

/**
 * 防抖
 * @param fn 
 * @param timeout 
 */
export const debounce = (fn: Function, timeout: number = 500) => {
    let timer: any;

    return () => {
        timer && clearTimeout(timer);
        timer = setTimeout(fn, timeout);
    }
}